package com.dddframework.mq.redis;

import cn.hutool.core.util.IdUtil;
import com.dddframework.core.context.ThreadContext;
import com.dddframework.core.contract.constant.ContextConstants;
import com.dddframework.core.utils.JsonKit;
import lombok.Data;

import java.io.Serializable;

/**
 * 消息body内容
 *
 * @author Liyj
 */
@Data
public class MQMessage<T> implements Serializable {
    /**
     * 租户ID
     */
    private String tenantId = ThreadContext.get(ContextConstants.TENANT_ID);
    private String systemId = ThreadContext.getOrDefault(ContextConstants.SYSTEM_ID, "0");
    /**
     * 消息key 可做唯一值
     */
    private String key = IdUtil.getSnowflakeNextIdStr();
    /**
     * 时间戳
     */
    private Long createTime = System.currentTimeMillis();
    private T body;

    public MQMessage(T body) {
        this.body = body;
    }

    @Override
    public String toString() {
        return JsonKit.toJsonClean(this);
    }
}
